package wx.wx.util;

import net.sf.json.JSONObject;
import wx.wx.entity.*;
import wx.wx.service.WxService;

public class CreateMenu {

    public static void main(String[] args) {
        //菜单对象
        Button btn = new Button();
        //第一个一级菜单
        btn.getButton().add(new ClickButton("一级点击", "1"));
        //第二个一级菜单
        btn.getButton().add(new ViewButton("一级跳转", "http://www.baidu.com"));
        //创建第三个一级菜单
        SubButton sb = new SubButton("有子菜单");
        //为第三个一级菜单增加子菜单
        sb.getSub_button().add(new PicPhotoOrAlbumButton("传图", "31"));
        sb.getSub_button().add(new ClickButton("点击", "32"));
        sb.getSub_button().add(new ViewButton("去网易", "http://news.163.com"));
        //加入第三个一级菜单
        btn.getButton().add(sb);

        JSONObject j = JSONObject.fromObject(btn);
        //准备url
        String url = " https://api.weixin.qq.com/cgi-bin/menu/create?access_token="+WxService.getAccessToken()+"";
        System.out.println("url:"+url);
        //发送请求
        String result = Utlis.post(url, j.toString());
        System.out.println(result);
    }

}
